/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.etrs.formathlon.vue.jsf.converter;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import net.etrs.formathlon.entity.formation.Session;
import net.etrs.formathlon.vue.jsf.utils.GeneralBean;

/**
 * Converter pour les sessions.
 * @author OPIF
 */
@ManagedBean
@ApplicationScoped
public class SessionConverter extends GeneralBean implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        return getFacadeAccessorBean().getSessionFacade().read(Long.parseLong(value));
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if(value instanceof Session){
            return ((Session)value).getId().toString();
        }
        else{
            return "";
        }
    }
    
}
